﻿using System.Linq;

namespace Yyyg.Models
{
    public class GoodType
    {
        public int TypeID { get; set; }
        public GoodType ParentType { get; set; }
        public string TypeName { get; set; }

        /// <summary>
        /// 根据Typeid递归查询类型
        /// </summary>
        /// <param name="typid"></param>
        /// <returns></returns>
        public static GoodType GetByTypeId(int typid)
        {
            if (typid <= 0) return null;
            GoodType gt = new GoodType();
            Goods_type t;
            using (LuckyEntities luck = new LuckyEntities())
            {
                t = luck.Goods_type.FirstOrDefault(r => r.Typeid == typid);
                if (t == null) return null;
            }
            gt.TypeID = t.Typeid;
            gt.TypeName = t.Typename;
            gt.ParentType = GetByTypeId(t.Parentid);
            return gt;
        }
    }
}
